'use strict';
const dayjs = require("dayjs");
module.exports = app => {
    const { INTEGER, DATE, STRING } = app.Sequelize;
    const Device = app.model.define(
      'Device',
          {
            id: {type: INTEGER, primaryKey: true, autoIncrement: true},
            type: STRING,
            name: STRING,
            number: STRING,
            department_id: INTEGER,
            manager_id: INTEGER,
            build_department_id: INTEGER,
            project: STRING,
            purpose: STRING,
            location: STRING,
            integrator: STRING,
            count: STRING,
            buy_time: DATE,
            warranty: STRING,
            maintain_cycle: STRING,
            status: STRING,
            stop_time: DATE,
            stop_reason: STRING,
            firmware: STRING,
            module: STRING,
            port_type: STRING,
            os_type: STRING,
            create_time: {
                  type: DATE,
                  get() {
                      return dayjs(this.getDataValue('create_time')).format('YYYY-MM-DD HH:mm:ss');
                  }
              },
            updated_time: {
                  type: DATE,
                  get() {
                      return dayjs(this.getDataValue('updated_time')).format('YYYY-MM-DD HH:mm:ss');
                  }
              }
          },
          {
              tableName: 'device',
              timestamps: true, // 启用时间戳(createdAt, updatedAt)
              updatedAt: 'updated_time', // 不想要 updatedAt
              createdAt: 'create_time', // 想要  createdAt 但是希望名称叫做 create_time
          }
    );
    return Device;
};
// 创建mysql建表语句
// CREATE TABLE `device` (
//   `id` int(11) NOT NULL AUTO_INCREMENT,
//   `type` varchar(255) DEFAULT NULL,
//   `name` varchar(255) DEFAULT NULL,
//   `number` varchar(255) DEFAULT NULL,
//   `department_id` int(11) DEFAULT NULL,
//   `manager_id` int(11) DEFAULT NULL,
//   `build_department_id` int(11) DEFAULT NULL,
//   `project` varchar(255) DEFAULT NULL,
//   `purpose` varchar(255) DEFAULT NULL,
//   `location` varchar(255) DEFAULT NULL,
//   `integrator` varchar(255) DEFAULT NULL,
//   `count` varchar(255) DEFAULT NULL,
//   `buy_time` datetime DEFAULT NULL,
//   `warranty` varchar(255) DEFAULT NULL,
//   `maintain_cycle` varchar(255) DEFAULT NULL,
//   `status` varchar(255) DEFAULT NULL,
//   `stop_time` datetime DEFAULT NULL,
//   `stop_reason` varchar(255) DEFAULT NULL,
//   `firmware` varchar(255) DEFAULT NULL,
//   `module` varchar(255) DEFAULT NULL,
//   `port_type` varchar(255) DEFAULT NULL,
//   `os_type` varchar(255) DEFAULT NULL,
//   `create_time` datetime DEFAULT NULL,
//   `updated_time` datetime DEFAULT NULL,
//   PRIMARY KEY (`id`)
// ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

